package com.my.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**again
 * Servlet implementation class Test
 */
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Test() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		out.println("app1 servlet");
		out.println("<html>");
		out.println("<head>");
		out.println("<title>Welcome to casTest2 sample System!</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>Welcome to casTest1 sample System!</h1>");
//		CASFilterRequestWrapper reqWrapper = new CASFilterRequestWrapper(request);
//		out.println("<p>The logon user:" + reqWrapper.getRemoteUser() + "</p>");
		HttpSession session = request.getSession();
//		out.println("<p>The logon user:"
//				+ session.getAttribute(CASFilter.CAS_FILTER_USER) + "</p>");
		out.println("<p>The logon user:"
				+ session
						.getAttribute("edu.yale.its.tp.cas.client.filter.user")
				+ "</p>");
		out.println("</body>");
		out.println("</html>");
		
		/*Assertion assertion = (Assertion) request.getSession().getAttribute(
				AbstractCasFilter.CONST_CAS_ASSERTION);
		if (null != assertion) {
			out.println(" Log | ValidFromDate =:"
					+ assertion.getValidFromDate() + "<br>");
			out.println(" Log | ValidUntilDate =:"
					+ assertion.getValidUntilDate() + "<br>");
			Map<Object, Object> attMap = assertion.getAttributes();
			out.println(" Log | getAttributes Map size = " + attMap.size()
					+ "<br>");
			for (Entry<Object, Object> entry : attMap.entrySet()) {
				out.println("     | " + entry.getKey() + "=:"
						+ entry.getValue() + "<br>");
			}

		}
		AttributePrincipal principal = assertion.getPrincipal();

		// AttributePrincipal principal = (AttributePrincipal) request
		// .getUserPrincipal();

		String username = null;
		out.print(" Log | UserName:");
		if (null != principal) {
			username = principal.getName();
			out.println("<span style='color:red;'>" + username + "</span><br>");
		}*/

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
